package myJs.api

import myJs.Implicits._
import myJs.myPkg.MyFetch
import org.scalajs.macrotaskexecutor.MacrotaskExecutor.Implicits._
import shared.tsPojo.TsPojo
import upickle.default._

/**
 * Created by yz on 7/5/2022
 */
object Analysis {

  import TsPojo.analysis._

  val baseUrl = s"${Api.apiUrl}/gepLiver/analysis"

  def cellLineDepImage(request: CellLineDepImage.Request) = {
    val url = s"${baseUrl}/cellLineDepImage"
    MyFetch.postRnText(url = s"${url}", data = write(request), headers = Map("Content-Type" -> "application/json")).map { str =>
      read[CellLineDepImage.Response](str)
    }
  }

  def cellLineScatterImage(request: CellLineScatterImage.Request) = {
    val url = s"${baseUrl}/cellLineScatterImage"
    MyFetch.postRnText(url = s"${url}", data = write(request), headers = Map("Content-Type" -> "application/json")).map { str =>
      read[CellLineScatterImage.Response](str)
    }
  }

  def survivalImage(request: SurvivalImage.Request) = {
    val url = s"${baseUrl}/survivalImage"
    MyFetch.postRnText(url = s"${url}", data = write(request), headers = Map("Content-Type" -> "application/json")).map { str =>
      read[SurvivalImage.Response](str)
    }
  }

  def comparisonImage(request: ComparisonImage.Request) = {
    val url = s"${baseUrl}/comparisonImage"
    MyFetch.postRnText(url = s"${url}", data = write(request), headers = Map("Content-Type" -> "application/json")).map { str =>
      read[ComparisonImage.Response](str)
    }
  }

}
